<?php
class Admin_Model_DbTable_region extends Zend_Db_Table_Abstract
{
	 protected $_name = 'hae_bdd_region';
	 protected $_sequence=true;
     protected $_primary='id';
     protected $_referenceMap=array(
	'country'=>array(
		'columns'=>array('countryId'),
		'refTableClass'=>'Admin_Model_DbTable_country',
		'refColumns'=>array('id'),
		'onDelete'=>self::RESTRICT,
		'onUpdate'=>self::RESTRICT
	)
	);
     
	public function addregion($status, $name_vi, $name_en, $name_ja, $name_cn, $name_fr, $countryId, $image)
	{
		$data = array(
		'name_vi' => $name_vi,
		'name_en' => $name_en,
		'name_ja' => $name_ja,
		'name_cn' => $name_cn,
		'name_fr' => $name_fr,
		'status'  => $status,
		'countryId'=> $countryId,
		'image' => $image,
		);
		$this->insert($data);
	}
	public function getregion($id)
	{
	    $id = (int)$id;
	    $row = $this->fetchRow('id=' . $id);
		if(!$row)
		{ 
			throw  new Exception("Could not find row {$id}");
		}
		return $row->toArray();
	}
	public function getallregion()
	{
		$select = $this->select();
		$select->setIntegrityCheck(false);
		$select->from($this->_name,"*");
		$select->join('hae_bdd_country', 'hae_bdd_country.id ='.$this->_name.'.countryId', 'title_en as country');
		return $this->fetchAll($select);
	}
	public function updateregion($id, $status, $name_vi, $name_en, $name_ja, $name_cn, $name_fr, $countryId, $image)
	{
		$data = array(
		'name_vi' => $name_vi,
		'name_en' => $name_en,
		'name_ja' => $name_ja,
		'name_cn' => $name_cn,
		'name_fr' => $name_fr,
		'status'  => $status,
		'countryId'=> $countryId,
		'image' => $image,
		);
		$this->update($data, 'id = '. (int)$id);
	}
	public function changestatus($id,$status)
	{
		$data = array(
		'status' => $status,
		);
		$this->update($data, 'id = '. (int)$id);
	}
	public function deleteregion($id)
    {
        return $this->delete('id =' . (int)$id);
    }
}
?>